<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty {pp_errormsg} function plugin
 *
 * File:       function.pp_errormsg.php<br>
 * Type:       function<br>
 * Name:       pp_errormsg<br>
 * Date:       24.Feb.2003<br>
 * Purpose:    Prints out a list of text input types<br>
 * Input:<br>
 *           - name       (optional) - string default "text"
 *           - values     (required) - array
 *           - options    (optional) - associative array
 *           - checked    (optional) - array default not set
 *           - separator  (optional) - ie <br> or &nbsp;
 *           - output     (optional) - the output next to each text button
 *           - assign     (optional) - assign the output as an array to this variable
 * Examples:
 * <pre>
 * {pp_errormsg values=$ids output=$names}
 * {pp_errormsg values=$ids name='box' separator='<br>' output=$names}
 * {pp_errormsg values=$ids checked=$checked separator='<br>' output=$names}
 * </pre>
 * @link http://smarty.php.net/manual/en/language.function.html.texts.php {pp_errormsg}
 *      (Smarty online manual)
 * @author     Christopher Kvarme <christopher.kvarme@flashjab.com>
 * @author credits to Monte Ohrt <monte at ohrt dot com>
 * @version    1.0
 * @param array
 * @param Smarty
 * @return string
 * @uses smarty_function_escape_special_chars()
 */
function smarty_function_pp_errormsg($params, &$smarty)
{
	require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');

	$value = '';
	$extra = '';
	
	foreach($params as $_key => $_val) {
		switch($_key) {
			case 'value':
				$$_key = (string)$_val;
				break;
			
			case 'text':
				$value = (string)$_val;
				break;
			
			case 'from':
				$value = $_val;
				break;
				
			case 'assign':
				break;
			
			default:
				if( !is_array($_val) ) {
					$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
				} else {
					$smarty->trigger_error("pp_errormsg: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
				}
				break;
		}
	}

	//
	$_html_result = smarty_function_pp_errormsg_output($value, $extra);

	return $_html_result;
}

function smarty_function_pp_errormsg_output($value, $extra) {
	global $LANGUAGE;
	
	if( substr($value, 0, strlen(':')) == ':' ) {
		$ks = explode(':', $value);
		if( sizeof($ks) == 2 ) {
			$value = isset($LANGUAGE[$ks['1']]) ? $LANGUAGE[$ks['1']] : $ks['1'];
		} else {
			$value = isset($LANGUAGE[$ks['1']][$ks['2']]) ? $LANGUAGE[$ks['1']][$ks['2']] : $ks['2'];
		}
	}
	
	//
	$_output = '';
	
    $_output .= '<span class="errormsg">' . smarty_function_escape_special_chars($value) . '</span>';

    return $_output;
}
//
?>
